home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / MEMBLOCK.BAT < prev    next >
DOS Batch File  |  1993-06-09  |  3KB  |  91 lines

  1. @echo OFF
  2. REM MemBlock - Examples CEnvi DOS program to walk through the list of
  3. REM            allocated memory.  This uses interrupts through the interrup()
  4. REM            function, and direct memory access using peekbuf().
  5. ECHO The following is a walk-through of your allocated memory blocks:
  6. cenvi %0.bat
  7. GOTO CENVI_EXIT
  8.  
  9. #define  MCB_HEADER_SIZE   16
  10. #define  ID_OFFSET         0
  11. #define  MORE_TO_FOLLOW    'M'   // set if more MCB follow in chain
  12. #define  LAST_MCB          'Z'   // if no more MCB in chain
  13. #define  PSP_SEG_OFFSET    1
  14. #define  SIZE_OFFSET       3
  15. #define  ENVIRONMENT_SEG_OFFSET  0x2C
  16.  
  17. /*************************************************************/
  18. /* Get access to the first memory block through undocumented */
  19. /* DOS interrupt to get the DIB (Dos Information Block.      */
  20. /*************************************************************/
  21. reg.ah = 0x52           // Get DIB address in ES:BX
  22. interrupt(0x21,reg)
  23. // The actual first mcb (memory control block) address is 4 bytes below
  24. // es:bx, or 16 bytes above the previous paragraph
  25. segment = PeekWord(reg.es - 1,reg.bx+14)
  26.  
  27.  
  28. /*************************************************************/
  29. /* Loop through all MCB's, displaying information about them */
  30. /*************************************************************/
  31. count = 0
  32. total = 0
  33. do {
  34.    printf("==========================================\n")
  35.    id = peek(Address(segment,ID_OFFSET))
  36.    printf("MCB number\t= %d\n",++count)
  37.    printf("ID\t\t= %c\n",id)
  38.    printf("MCB address\t= %04X:0000\n",segment)
  39.    printf("Memory address\t= %04X:0000\n",MemorySeg = segment+1)
  40.    printf("PSP address\t= %04X:0000\n",PspSeg = PeekWord(segment,PSP_SEG_OFFSET))
  41.    size = PeekWord(segment,SIZE_OFFSET)
  42.    printf("Size\t\t= %d paragraphs (%d bytes)\n",size,size*16)
  43.    if ( 0 != PSPSeg ) {
  44.       EnvironmentBlock = PeekWord(PspSeg,ENVIRONMENT_SEG_OFFSET)
  45.       if EnvironmentBlock == MemorySeg
  46.          ShowEnvironmentBlock(EnvironmentBlock)
  47.    }
  48.    // increment segment to point to the next MCB
  49.    segment += size + 1
  50.    total += size + 1
  51. } while( id == MORE_TO_FOLLOW )
  52.  
  53.  
  54. /***************/
  55. /* SHOW TOTALS */
  56. /***************/
  57. printf("==========================================\n")
  58. printf("Totals:\n")
  59. printf("MCB Count\t= %d\n",count)
  60. printf("Memory\t\t= %d paragraphs (%d bytes)\n",total,total*16)
  61.  
  62.  
  63. /*****************************************/
  64. /* FUNCTION TO DISPLAY ENVIRONMENT BLOCK */
  65. /*****************************************/
  66. ShowEnvironmentBlock(seg)
  67. {
  68.    printf("Environment block at %04X:0000\n",seg)
  69.    for ( Offset = 0; 0 != peek(Address(seg,Offset)); Offset++ ) {
  70.       EString = peek(Address(seg,Offset),1000)
  71.       Offset += strlen(EString)
  72.       printf(" %s\n",EString)
  73.    }
  74.    printf("Program: ")
  75.    if ( 0x0001 == PeekWord(seg,++Offset) ) {
  76.       // the full path and name of the calling program follows
  77.       printf("%s\n",peek(Address(seg,Offset+2),1000))
  78.    } else
  79.       printf("Unknown\n")
  80. }
  81.  
  82. /***********************************************/
  83. /* UTILITY FUNCTIONS USED IN THE ABOVE PROGRAM */
  84. /***********************************************/
  85. PeekWord(segment,offset)
  86. {
  87.    return( peek(Address(segment,offset),UWORD16) );
  88. }
  89.  
  90. :CENVI_EXIT
  91.